/*
 * GoogleSyncRecord keeps track of which files have been
 * sync by the calling process. It mainly uses hashmap mechanism for
 * the purpose of fast access.
 * 
 */
// @author A0105514U
/** @author A0105514U */

package gCalEngine;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class GoogleSyncRecord {
	private Map<String,Boolean> record;
	
	public GoogleSyncRecord(ArrayList<String> fileNameList){
		record = new HashMap<String,Boolean>();
		Iterator<String> it = fileNameList.iterator();
		while(it.hasNext()){
			record.put(it.next(), false);
		}
	}
	
	// mark a filename as sync
	public void setSync(String fileName){
		record.put(fileName, true);
	}
	
	// return whether a given filename has been sync in this record or not
	public boolean getRecord(String fileName){
		if(record.containsKey(fileName)){
			return record.get(fileName);
		}else{
			return false;
		}
	}
	
	
	// Get the list of file names that have not been setSync()
	public ArrayList<String> getUnsyncFileNameAsList(){
		Iterator<Entry<String, Boolean>> it = record.entrySet().iterator();
		ArrayList<String> fileNameList = new ArrayList<String>();
		Entry<String,Boolean> e;
		
		while(it.hasNext()){
			e = it.next();
			if(!e.getValue()){
				fileNameList.add(e.getKey());
			}
		}
		return fileNameList;
	}
}
